using SharePoint.Security.ConfigAnalyzer.Engine.Base;
using SharePoint.Security.ConfigAnalyzer.Engine.Common;
using Microsoft.SharePoint.Administration;

namespace SharePoint.Security.ConfigAnalyzer.Engine.Rules.Others
{
    public class DefaultDBWindowsAuth : BaseRule
    {
        public DefaultDBWindowsAuth()
        {
            RuleInfo = new RuleInfo
                           {
                               Title = "DB is using Windows AuthN",
                               Description = "Ensure Sharepoint is configured to connect with SQL server DB using Windows Authentication (Central Administration > Default Database Server)",
                               ExpectedValue = "Should use Windows Auth"
                           };
        }

        #region Overrides of BaseRule

        public override void Validate()
        {
            var value = ObjectHelper.Farm.Services.GetValue<SPWebService>();
            if (string.IsNullOrEmpty(value.DefaultDatabaseUsername) && string.IsNullOrEmpty(value.DefaultDatabasePassword))
            {
                Status = Status.Pass;
                CurrentValue = "Using Windows Auth as username and password are empty.";
            }
            else
            {
                Status = Status.Fail;
                CurrentValue = "Not using Windows Auth as username and password are not empty.";
            }
        }

        #endregion
    }
}